﻿@{
    ViewBag.Title = "员工选择";
    Layout = "~/Views/Shared/_FormLayout.cshtml";
}

@section HeadIncluder 
{
    <link rel="stylesheet" type="text/css" href=@Url.Content("~/Scripts/skins/default.css")   />
} 

<div id="container" style="margin-right: 10px;">
    <div id="grid" style="width: 400px; height: 300px;">
    </div>
</div>
<div class="ui_buttons" style="background: #d4e4f6; padding-right: 20px;">

    <input id="subbtn" type="button" value="确定" class="ui_state_highlight" />
    <input type="button" value="取消" onclick="cancel();" />
</div>
<script type="text/javascript">
    $(document).ready(function () {
        loadData();
        
        $("#subbtn").click(function () {
            var grid = $("#grid").data("kendoGrid");
            var items = grid.select();
            if (items.length == 0) {
                $.dialog.alert("你当前没有选择记录！");
                return;
            }
            var arr = new Array();
            $.each(items, function (i, item) {
                var obj = new Object();
                obj.EMPCode = item.cells[0].textContent;
                obj.RefCode = item.cells[1].textContent;
                obj.Name = item.cells[2].textContent;
                arr.push(obj);
            });
            window.top.refresh(arr);
            window.top.oDG.close();

        });
    });
  
    function loadData() {
        $("#grid").kendoGrid({
            selectable: '@(string.IsNullOrEmpty(Request["multiple"])?"row":"multiple,row")',
            dataSource: {
                serverPaging: true,
                pageSize: 10,
                transport: {
                    read: {
                        url: '@Url.Action("GetEmployeeList", "Form")',
                        type: "POST",
                        dataType: "json"
                    }
                },
                schema: {
                    //取出資料陣列
                    data: function (d) { return d.Data; },
                    //取出資料總筆數(計算頁數用)
                    total: function (d) { return d.TotalCount; }
                }
            },
            height: 600,
           
            pageable: {
                refresh: true,
                pageSizes: true
            },
            sortable: true,
            dataBinding: function (e) {
                for (var i = 0; i < e.items.length; i++) {
                    if (e.items[i].Gender == "W")
                        e.items[i].Gender = "女";
                    else
                        e.items[i].Gender = "男";
                }
            },
            pageable: {
                refresh: true,
                pageSizes: true
            },
            columns: [
                 { field: "EMPCode", title: "系统编号" },
                { field: "RefCode", title: "员工编号" },
                { field: "ChineseName", title: "名称" },
                { field: "Email", title: "Email" },
                  { field: "UserID", title: "UserID", hidden: true }
            ]
        });
    }

    function cancel() {
        window.top.oDG.close();
    };
</script>

